<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .wrap {
      width: 1072px;
      height: 400px;
      margin: 50px auto;
    }

    .wrap img {
      float: left;
      border: 1px solid black;
      margin-right: 20px;
    }

    .top {
      float: left;
      width: 600px;
      height: 220px;
      border-bottom: 1px solid #bbb;
      font-family: 'Microsoft yahei';
    }

    .top p span {
      font-size: 14px;
      color: .666;
      border: 1px solid #999;
      display: inline-block;
      padding: 8px;
      cursor: pointer;
    }

    .top p span.on {
      border: 2px solid #f60;
      padding: 7px;
      background: url(images/on.png) no-repeat right bottom;
    }
  </style>
</head>

<body>
  <div class="wrap">
    <img src="images/black.jpg" alt="">
    <div class="top">
      <p class="color">
        <label class="">颜色</label>
        <span class="on">黑色</span>
        <span class="">白色</span>
        <span class="">红色</span>
        <span class="">黄色</span>
        <span class="">紫色</span>
        <span class="">绿色</span>
      </p>
      <p class="rom">
        <label class="">内存</label>
        <span class="on">64GB</span>
        <span class="">128GB</span>
        <span class="">256GB</span>
      </p>
      <p class="banben">
        <label>版本</label>
        <span class="on">全网通</span>
        <span>移动版</span>
        <span>联通版</span>
        <span>电信版</span>
      </p>
    </div>

  </div>


  <script>
    const imgArr = ['images/black.jpg', 'images/white.jpg', 'images/red.jpg', 'images/yellow.jpg', 'images/purple.jpg', 'images/green.jpg'];

    //1.颜色选择
    const colorArr = document.querySelectorAll('.color span')
    for (let i = 0; i < colorArr.length; i++) {
      colorArr[i].onclick = function () {
        //排他思想修改样式
        document.querySelector('.color .on').classList.remove('on')
        this.classList.add('on')
        //修改图片
        document.querySelector('.wrap>img').src = imgArr[i]
      }
    }


    //2.内存选择
    const spanArr = document.querySelectorAll('.rom span')
    for (let i = 0; i < spanArr.length; i++) {
      spanArr[i].addEventListener('click', function () {
        //排他思想修改样式
        document.querySelector('.rom .on').classList.remove('on')
        this.classList.add('on')

      })
    }


    //3.版本选择
    const banbenArr = document.querySelectorAll('.banben span')
    for (let i = 0; i < banbenArr.length; i++) {
      banbenArr[i].addEventListener('click', function () {
        //排他思想修改样式
        document.querySelector('.banben .on').classList.remove('on')
        this.classList.add('on')
      })
    }



  </script>

</body>

</html>